from google.appengine.ext import db
from bts import core

class Topic(db.Model):
    name = db.StringProperty(required=True)

class BlogPost(db.Model):
    topic = db.ReferenceProperty(Topic, collection_name="blog_entries",
                                 required=True)
    title = db.StringProperty(required=True)
    body = db.TextProperty(required=True)
    date_posted = db.DateProperty(auto_now_add=True)
    materialized_property = core.materialized(db.StringProperty(),
                                              'derived_property')
    bts_fields = [
            {'field': 'title', 'weight': 4, 'stem': True, 'keepunstemmed': True, 'startswith': True},
            {'field': 'body', 'weight': 1, 'stem': True},
            {'field': 'materialized_property', 'weight': 1, 'stem': True},
            {'field': 'topic'},
            {'field': 'date_posted'}
            ]

    @property
    def derived_property(self):
        return "i derived myself"